const connection = require("../app/database")

class CommentService {
  async create(userId, content, momentId, commentId) {
    // 预处理语句
    const statement =
      "INSERT INTO comment (content, user_id, comment_id, moment_id) VALUES (?, ?, ?, ?);"
    // 执行sql语句
    const [result] = await connection.execute(statement, [
      content,
      userId,
      commentId,
      momentId,
    ])
    return result
  }

  async remove(userId, commentId) {
    // 预处理语句
    const statement = "DELETE FROM comment WHERE user_id = ? AND id = ?;"
    // 执行sql语句
    const [result] = await connection.execute(statement, [userId, commentId])
    return result
  }
}

module.exports = new CommentService()
